<?php
/**
 * Punny - The most easy-to-use PHP MVC framework
 *
 * Copyright (c) 2010
 *
 * @author email :lx.xin@qq.com
 */
 require('BaseController.php');
 class MessageController extends BaseController {
	function init(){
		parent::init();
	}
	/*
	 * 显示留言界面
	 */
	function indexAction(){
		echo $this->view->render('message.html');
	}
	/*
	 * 添加留言
	 */
	 function addAction(){
	 	$filter=array(
				'*'=>'StringTrim'					
			);
			$validate=array(
					'author'=>array(
						array('StringLength',1,100),
						Zend_Filter_Input::MESSAGES=>array(array(
							Zend_Validate_StringLength::INVALID=>"请输入一个合法的字符串",
							Zend_Validate_StringLength::TOO_SHORT=>"请输入字符长度为1-100",
							Zend_Validate_StringLength::TOO_LONG=>"请输入字符长度为1-100"	
					))
					),
					'email'=>array('NotEmpty','message'=>array(
						Zend_Validate_NotEmpty::IS_EMPTY=>"不能为空"
					)),
					'title'=>array('NotEmpty','message'=>array(
						Zend_Validate_NotEmpty::IS_EMPTY=>"不能为空"
					)),
					'content'=>array('NotEmpty','message'=>array(
						Zend_Validate_NotEmpty::IS_EMPTY=>"不能为空"
					))
				);
			$input= new Zend_Filter_Input($filter,$validate,$this->getRequest()->getPost());
			if($input->isValid()){
				require('./library/Custom/function.inc.php');				
				$data=$input->getEscaped();
				$message=new Message();
				$data['ip']=getip();
				$data['posttime']=time();
				$message->addMessage($data);
				echo "<script language='javascript'>alert('Add success!');window.history.back(-1);</script>";
			}
			else{
				echo "<script language='javascript'>alert('Add error,return check');history.go(-1);</script>";
				exit;
			}

	 }

 }






 ?>